import request from '@/components/hzjc/utils/request.js'

let user = {}

user.login = {
	/**
	 * 登录注册
	 * @param {int} type 登录方式 1--验证码登录 2--账号密码登录
	 * @param {string} mobilePhone 手机号
	 * @param {string} code 验证码
	 * @param {string} password 密码
	 * @param {int} lastUserId 上级用户ID
	 * @date 2023-02-15
	 */
	login: function(type, mobilePhone, code, password, lastUserId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Login/login', {
				type: type,
				mobile_phone: mobilePhone,
				code: code,
				password: password,
				last_user_id: lastUserId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	}
}

user.mpWeixin = {
	/**
	 * 更新用户信息
	 * @param {string} headImgUrl 头像
	 * @param {string} nickName 昵称
	 * @date 2023-04-03
	 */
	updateUserInfo: function(headImgUrl, nickName) {
		return new Promise((resolve, reject) => {
			request.getData('base/mpweixin/api/User/updateUserInfo', {
				head_img_url: headImgUrl,
				nick_name: nickName
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	}
}

/**
 * 获取用户信息
 * @date 2022-12-27
 */
user.getUserInfo = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/getUserInfo').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新用户信息
 * @param {object} data 需要请求的数据
 * @date 2022-12-27
 */
user.updateUserInfo = function(data) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/updateUserInfo', data, {
			loading: true,
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}


/**
 * 获取用户账号设置
 * @date 2022-12-27
 */
user.getAccountConfig = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/getAccountConfig').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新用户个性化开关状态
 * @param {int} isPersonalRecommend 个性化推荐开关是否打开
 * @date 2022-12-27
 */
user.updateAccountConfig = function(isPersonalRecommend) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/updateAccountConfig', {
			is_personal_recommend: isPersonalRecommend
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 退出登录
 * @date 2022-12-27
 */
user.logout = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Login/logout', {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 注销账户
 * @date 2022-12-27
 */
user.deleteUser = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/deleteUser', {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新用户信息
 * @date 2022-12-27
 */
user.getAccountInfo = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/getAccountInfo').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取用户手机号
 * @date 2022-10-09
 */
user.getMobilePhone = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/User/getMobilePhone').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 验证旧手机号
 * @param {string} mobilePhone 手机号
 * @param {string} code 验证码
 * @date 2022-10-10
 */
user.verifyOldMobilePhone = function(mobilePhone, code) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Login/verifyOldMobilePhone', {
			mobile_phone: mobilePhone,
			code: code
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 验证旧手机号
 * @param {string} mobilePhone 新手机号
 * @param {string} mobilePhoneOld 旧手机号
 * @param {string} code 验证码
 * @date 2022-10-10
 */
user.bindNewMobilePhone = function(mobilePhone, mobilePhoneOld, code) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Login/bindNewMobilePhone', {
			mobile_phone: mobilePhone,
			mobile_phone_old: mobilePhoneOld,
			code: code
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 修改密码
 * @param {string} mobilePhone 新手机号
 * @param {string} code 验证码
 * @param {string} password 密码
 * @param {string} password 确认密码
 * @date 2022-10-12
 */
user.updatePassword = function(mobilePhone, code, password, passwordConfirm) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Login/updatePassword', {
			mobile_phone: mobilePhone,
			code: code,
			password: password,
			password_confirm: passwordConfirm,
		}, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取用户支付宝信息
 * @date 2022-11-04
 */
user.getAlipay = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Alipay/getAlipay').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新用户支付宝信息
 * @param {object} data 信息
 * @date 2022-11-04
 */
user.updateAlipay = function(data) {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Alipay/updateAlipay', data, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 是否绑定支付宝
 * @date 2022-11-04
 */
user.isBindAliPay = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/user/api/Alipay/isBindAliPay').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

user.wxpay = {
	/**
	 * 获取用户微信信息
	 * @date 2023-02-16
	 */
	getWxpay: function() {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Wxpay/getWxpay').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 更新用户微信信息
	 * @param {object} data 信息
	 * @date 2023-02-16
	 */
	updateWxpay: function(data) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Wxpay/updateWxpay', data, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 是否绑定微信
	 * @date 2023-02-16
	 */
	isBindWxpay: function() {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Wxpay/isBindWxpay').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	}
}

/**
 * APP发起三方授权
 * @param {object} data 需要请求的数据
 * @date 2022-12-27
 */
user.updateThirdAuthInfo = function(data) {
	return new Promise((resolve, reject) => {
		request.getData('base/app/api/ThirdAuth/updateThirdAuthInfo', data, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * APP发起三方授权
 * @param {string} type 类型 weixin--微信 qq--QQ sinaweibo--新浪微博 apple--苹果
 * @date 2022-12-27
 */
user.deleteThirdAuthInfo = function(type) {
	return new Promise((resolve, reject) => {
		request.getData('base/app/api/ThirdAuth/deleteThirdAuthInfo', {
			type: type
		}, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}


/**
 * 获取用户信息
 * @date 2022-12-27
 */
user.isSubscribeWeixin = function() {
	return new Promise((resolve, reject) => {
		request.getData('base/mpweixin/api/User/isSubscribeWeixin').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新抖音小程序用户信息
 * @param {object} data 用户信息
 * @date 2022-12-28
 */
user.updateMpToutiaoUserInfo = function(data) {
	return new Promise((resolve, reject) => {
		request.getData('base/mptoutiao/api/User/updateUserInfo', data).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 更新支付宝小程序用户信息
 * @param {object} data 用户信息
 * @date 2022-12-28
 */
user.updateMpAlipayUserInfo = function(data) {
	return new Promise((resolve, reject) => {
		request.getData('base/mpalipay/api/User/updateUserInfo', data).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 地址
 */
user.address = {
	/**
	 * 添加/编辑用户地址
	 * @param {object} data 用户地址信息
	 * @date 2023-02-03
	 */
	updateAddress: function(data) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/updateAddress', data, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取用户地址列表
	 * @param {int} addressId 地址ID
	 * @date 2023-02-03
	 */
	listAddress: function(addressId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/listAddress', {
				address_id: addressId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取用户地址
	 * @param {int} addressId 地址ID
	 * @date 2023-02-03
	 */
	getAddress: function(addressId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/getAddress', {
				address_id: addressId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 删除地址
	 * @param {int} addressId 地址ID
	 * @date 2023-02-03
	 */
	deleteAddress: function(addressId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/deleteAddress', {
				address_id: addressId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取用户是否添加过地址
	 * @date 2023-02-03
	 */
	isHasAddress: function() {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/isHasAddress').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 设置默认地址
	 * @param {int} addressId 地址ID
	 * @date 2023-02-03
	 */
	setDefaultAddress: function(addressId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/setDefaultAddress', {
				address_id: addressId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 取消默认地址
	 * @param {int} addressId 地址ID
	 * @date 2023-02-03
	 */
	cancelDefaultAddress: function(addressId) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/cancelDefaultAddress', {
				address_id: addressId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 地址转经纬度和省市区
	 * @param {string} address 地址
	 * @date 2023-02-03
	 */
	addressToLocation: function(address) {
		return new Promise((resolve, reject) => {
			request.getData('base/user/api/Address/addressToLocation', {
				address: address
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},
}

export default user